<?php

namespace App\Http\Controllers;

use Yangyifan\Response\ResponseHelper;
use Yangyifan\BuildDom\Form\{
    Form, Option\Option
};
use Yangyifan\BuildDom\Form\FormItem\DatePicker\{
    DatePicker, MonthPicker, RangePicker
};
use Yangyifan\BuildDom\Form\FormItem\Input\{
    Input, InputNumber, Password
};
use Yangyifan\BuildDom\Form\FormItem\{
    FormItemConst, Rate\Rate, Radio\RadioGroup, Checkbox\CheckboxGroup, Select\Select, SwitchItem\SwitchItem, Cascader\Cascader, Slider\Option\Marks, Slider\Slider, TimePicker\TimePicker, Transfer\Option\TransferItem, Transfer\Transfer, TreeSelect\TreeSelect
};

class FormController extends Controller
{
    public function index()
    {
        $form = Form::create()
            ->setItem(function (Select $select) {
                return $select->setLabel('角色')->setName('select')
                    ->addOptions(function (Option $option) {
                        return $option->setLabel('超管')->setValue('超管')
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('管理员')->setValue('管理员');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('运维')->setValue('运维');
                            });
                    })
                    ->addOptions(function (Option $option) {
                        return $option->setLabel('运营')->setValue('运营')->setChildren(function (Option $option) {
                            return $option->setLabel('运营经理')->setValue('运营经理');
                        })->setChildren(function (Option $option) {
                            return $option->setLabel('运营主管')->setValue('运营主管');
                        });
                    });
            })
            ->setItem(function (Transfer $transfer) {
                return $transfer->setName('transfer')->setLabel('穿梭框')->setTitles('左侧', '右侧')->setOperations('左侧描述', '右侧描述')
                    ->setDataSource(function (TransferItem $transferItem) {
                        return $transferItem->setKey(1)->setTitle('item 1')->setDescription('item 1');
                    })
                    ->setDataSource(function (TransferItem $transferItem) {
                        return $transferItem->setKey(2)->setTitle('item 2')->setDescription('item 2');
                    })
                    ->setDataSource(function (TransferItem $transferItem) {
                        return $transferItem->setKey(3)->setTitle('item 3')->setDescription('item 3');
                    })
                    ->setTargetKeys([1, 2])
                    ->setSelectedKeys(1, 3);
            })
            ->setItem(function (TreeSelect $treeSelect) {
                return $treeSelect
                    ->setLabel('树形选择器')
                    ->setName('tree_name')
                    ->setShowCheckedStrategy(FormItemConst::SHOW_ALL)
                    ->setMultiple(true)
                    ->setTreeCheckable(true)
                    ->setValue('0-0', '0-1-0')
                    ->setTreeData(function (Option $option) {
                        return $option->setLabel('节点1')->setValue('0-0')->setKey('0-0')->setChildren(function (Option $option) {
                            return $option->setLabel('节点1-1')->setValue('0-0-0')->setKey('0-0-0');
                        });
                    })
                    ->setTreeData(function (Option $option) {
                        return $option->setLabel('节点2')->setValue('0-1')->setKey('0-1')->setChildren(function (Option $option) {
                            return $option->setLabel('节点2-1')->setValue('0-1-0')->setKey('0-1-0');
                        });
                    });
            })
            ->setItem(function (Cascader $cascader) {
                return $cascader->setName('city_info')->setLabel('所在城市')->setValue('上海')->setValue('上海市')->setValue('宝山区')->addOptions(function (Option $option) {
                    return $option->setLabel('上海')->setValue('上海')->setChildren(function (Option $option) {
                        return $option->setLabel('上海市')->setValue('上海市')
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('宝山区')->setValue('宝山区');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('黄浦区')->setValue('黄浦区');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('徐汇区')->setValue('徐汇区');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('虹口区')->setValue('虹口区');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('浦东新区')->setValue('浦东新区');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('长宁区')->setValue('长宁区');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('静安区')->setValue('静安区');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('松江区')->setValue('松江区');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('闵行区')->setValue('闵行区');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('金山区')->setValue('金山区');
                            })
                            ->setChildren(function (Option $option) {
                                return $option->setLabel('奉贤区')->setValue('奉贤区');
                            });
                    });
                });
            })
            ->setItem(function (Input $input) {
                return $input->setName('user_name')->setLabel('用户名');
            })->setItem(function (Password $password) {
                return $password->setName('password')->setLabel('密码');
            })->setItem(function (InputNumber $inputNumber) {
                return $inputNumber->setName('number')->setLabel('数值输入框')->setDefaultValue(99);
            })->setItem(function (Rate $rate) {
                return $rate->setName('rate')->setLabel('评分');
            })->setItem(function (Slider $slider) {
                return $slider->setName('slide')->setLabel('滑块')->setRange(true)->setMin(0)->setMax(100)
                    ->setMarks(function (Marks $marks) {
                        return $marks->setNumber(10)->setLabel('10度');
                    })
                    ->setMarks(function (Marks $marks) {
                        return $marks->setNumber(20)->setLabel('20度');
                    })
                    ->setMarks(function (Marks $marks) {
                        return $marks->setNumber(50)->setLabel('50度');
                    })
                    ->setMarks(function (Marks $marks) {
                        return $marks->setNumber(100)->setLabel('100度');
                    });
            })->setItem(function (SwitchItem $switchItem) {
                return $switchItem->setName('status')->setLabel('状态')->setCheckedChildren('开启')->setUnCheckedChildren('关闭')->setChecked(true);
            })->setItem(function (RadioGroup $radioGroup) {
                return $radioGroup->setName('role')->setLabel('角色')->setValue(2)
                    ->addOptions(function (Option $option) {
                        return $option->setLabel('超级管理员')->setValue(1);
                    })->addOptions(function (Option $option) {
                        return $option->setLabel('管理员')->setValue(2);
                    });
            })->setItem(function (CheckboxGroup $checkboxGroup) {
                return $checkboxGroup->setName('limit')->setLabel('角色')->setValue(1)
                    ->addOptions(function (Option $option) {
                        return $option->setLabel('超级管理员')->setValue(1);
                    })->addOptions(function (Option $option) {
                        return $option->setLabel('管理员')->setValue(2);
                    });
            })
            ->setItem(function (TimePicker $timePicker) {
                return $timePicker->setLabel('时间选择器')->setName('time_picker')->setValue('12-09-12');
            })
            ->setItem(function (DatePicker $datePicker) {
                return $datePicker->setName('created_time')->setLabel('创建时间')->setValue(date('Y-m-d'));
            })
            ->setItem(function (MonthPicker $monthPicker) {
                return $monthPicker->setName('month')->setLabel('月份')->setValue(date('y-m', strtotime('-1 years')));
            })
            ->setItem(function (RangePicker $rangePicker) {
                return $rangePicker->setName('range')->setLabel('范围时间选择器');
            });

        return ResponseHelper::successResponse('', $form->render());
    }
}
